<% 
@servlet.getResponse().setStatus(500);

var message = @ObjectUtils.toString(@request.getAttribute("message"));

var ex;
if (isBlank(message)){
	ex = @ExceptionUtils.getThrowable(request);
	if (ex != null){
		for (e in [ex, ex.cause!, ex.cause.cause!]){
			if (@StringUtils.startsWith(e.message!, "msg:")){
				message = @StringUtils.replace(e.message!, "msg:", "");
				break;
			}
		}
		@org.slf4j.LoggerFactory.getLogger("error/500").error(ex.message, ex);
	}
}

if (isBlank(message)){
	message = text('sys.error.500.message');
}

// 如果是异步请求或是手机端，则直接返回信息
if (@Servlets.isAjaxRequest(request)) {
	print(@Servlets.renderResult(@Global.FALSE, message));
}

// 输出异常信息页面
else {
%>
<% layout('/layout/default.html', {title: '500 - '+text('sys.error.500.title'), libs: ['layout']}){ %>
<!-- Main content -->
<section class="content">

	<div class="error-page">
		<h2 class="headline text-red">500</h2>

		<div class="error-content">
			<h3><i class="fa fa-warning text-red"></i> ${message} </h3>

			<p>
                ${text('sys.error.500.message.p1')}<a href="${ctx}">返回主页</a>
			</p>

			<form class="search-form">
				<div class="input-group">
					<input type="text" name="search" class="form-control" placeholder="Search">

					<div class="input-group-btn">
						<button type="submit" name="submit" class="btn btn-danger btn-flat"><i class="fa fa-search"></i>
						</button>
					</div>
				</div>
				<!-- /.input-group -->
			</form>
		</div>
	</div>
	<!-- /.error-page -->

</section>
<!-- /.content -->
<div style="text-align: center;">
    <% var productName = @Global.getProperty('productName'), productVersion = @Global.getProperty('version'); %>
    <strong>Copyright &copy; 2017-${@DateUtils.getYear()} <a href="http://jsite.org.cn">${productName}</a>.</strong> All rights
    reserved.
</div>
<% if (@ObjectUtils.toBoolean(@Global.getProperty('error.page.printErrorInfo', 'true'))){ %>
<div class="box mt20">
    ${@StringUtils.toHtml(@ExceptionUtils.getStackTraceAsString(ex))}<br/>
    此异常信息若不想输出，可打开jsite-core.properties文件，设置error.page.printErrorInfo=false即可
</div>
<% } %>
<% } %>
<% } %>